﻿@model Forum.Web.Models.PostDetailModel
@{
    ViewBag.Title = "ENode论坛-帖子详情";
    Layout = "~/Views/Shared/_SimpleLayout.cshtml";
}
<div ng-controller="PostDetailController">
    <div>
        <div class="post_title">
            @Model.Subject
        </div>
        <div class="post-item-header">
            <div class="pull-left">
                <span>#楼主</span>
                <span style="margin-right:5px">@Model.CreatedOn</span>
                @if (!string.IsNullOrEmpty(Model.AuthorName))
                {
                    @Html.ActionLink(Model.AuthorName, "index", new { authorId = Model.AuthorId })
                }
            </div>
            <div class="pull-right">
                @if (Model.AuthorId == ViewBag.CurrentAccountId)
                {
                    <a href="#" ng-click="showEditPostDialog()" style="margin-left:5px">编辑</a>
                }
                @if (HttpContext.Current.Request.IsAuthenticated)
                {
                <a href="#" ng-click="showNewReplyDialog()">回复</a>
                }
            </div>
        </div>
        <div class="post-item-body">
            @Model.Body
        </div>
    </div>
    @foreach (var reply in Model.Replies)
    {
        <div>
            <div class="reply-item-header">
                <div class="pull-left">
                    <span>#@reply.Floor@Html.Raw("楼")</span>
                    @if (@reply.AuthorId == Model.AuthorId)
                    {
                    <span>[楼主]</span>
                    }
                    <span style="margin-left:5px; margin-right:5px">@reply.CreatedOn</span>
                    @if (!string.IsNullOrEmpty(reply.AuthorName))
                    {
                    @Html.ActionLink(reply.AuthorName, "index", new { authorId = reply.AuthorId })
                    }
                </div>
                <div class="pull-right">
                    @if (reply.AuthorId == ViewBag.CurrentAccountId)
                    {
                    <a href="#" ng-click="showEditReplyDialog('@reply.Id')" style="margin-left:5px">编辑</a>
                    }
                    @if (HttpContext.Current.Request.IsAuthenticated)
                    {
                    <a href="#" ng-click="showNewSubReplyDialog('@reply.Id')">回复</a>
                    }
                </div>
            </div>
            <div class="reply-item-body">
                @reply.Body
            </div>
        </div>
    }
    @if (HttpContext.Current.Request.IsAuthenticated)
    {
        <button class="btn btn-primary btn-lg" data-toggle="modal" ng-click="showNewReplyDialog()">发表回复</button>
    }
    <div class="modal fade" id="float-box-editingPost">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">编辑帖子</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label for="editingPost_subject" class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-9">
                                <input type="text" maxlength="256" id="editingPost_subject" class="form-control" ng-model="editingPost.subject" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="editingPost_body" class="col-sm-2 control-label">内容</label>
                            <div class="col-sm-9">
                                <textarea id="editingPost_body" maxlength="1000" class="form-control" ng-model="editingPost.body" rows="5"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"></label>
                            <div class="col-sm-9">
                                <span class="error" ng-show="errorMsg != ''">{{errorMsg}}</span>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" ng-click="updatePost()">提交</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <div class="modal fade" id="float-box-newReply">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">发表回复</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label for="newReply_body" class="col-sm-2 control-label">内容</label>
                            <div class="col-sm-9">
                                <textarea id="newReply_body" maxlength="1000" class="form-control" ng-model="newReply.body" rows="10"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"></label>
                            <div class="col-sm-9">
                                <span class="error" ng-show="errorMsg != ''">{{errorMsg}}</span>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" ng-click="submitReply()">提交</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <div class="modal fade" id="float-box-editingReply">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">编辑回复</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label for="editingReply_body" class="col-sm-2 control-label">内容</label>
                            <div class="col-sm-9">
                                <textarea id="editingReply_body" maxlength="1000" class="form-control" ng-model="editingReply.body" rows="10"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"></label>
                            <div class="col-sm-9">
                                <span class="error" ng-show="errorMsg != ''">{{errorMsg}}</span>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" ng-click="updateReply()">提交</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</div>

@section Scripts {
    <script type="text/javascript">
        var postId = '@Model.Id';
    </script>
    <script type="text/javascript" src="@Url.Content("~/content/controllers/post-detail-controller.js")"></script>
}